﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using ChatJs.Lib;
using IDotNet;

namespace chatjs
{
    public class CustomerAuthorizeAttribute : AuthorizeAttribute
    {
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (!httpContext.Request.IsAuthenticated)
            {
                var key = "Users";
                var userId = RandomHelper.Next(10000,Int32.MaxValue);
                var info = new ChatUserInfo()
                {
                    Id = userId,
                    LastActiveOn = DateTime.UtcNow,
                    Name = "Test_"+userId,
                    Email = "test",
                    ProfilePictureUrl = "",
                    // RoomId = roomId.ToString(),
                    Status = ChatUserInfo.StatusType.Online,
                    Url = "",
                };
                RedisHelper.SetHash(key, userId.ToString(), info);
                FormsAuthentication.SetAuthCookie(userId.ToString(), false);
            }
            return true;
        }
    }
}